package com.example.esc_im_client.ui.home;

import android.content.Intent;
import android.content.Context;
import com.alibaba.fastjson.JSONObject;
import com.alipay.mobile.antcube.CubeService;
import com.antfin.cube.antcrystal.api.CubeJSCallback;
import com.antfin.cube.antcrystal.api.CubeModule;
import com.antfin.cube.platform.api.JsMethod;
import com.example.esc_im_client.App;
import com.example.esc_im_client.MainActivity;
import com.example.esc_im_client.ui.newview.NewViewActivity;

/**
 * @ClassName: CustomCubeModule
 * @Description:
 * @Author: 墨渍
 * @Date: 2024/3/6 8:59
 **/
public class CustomCubeModule extends CubeModule {
    private static final String TAG = CustomCubeModule.class.getSimpleName();

    // 注解，uiThread 表示是否在主进程回调
    @JsMethod(uiThread = true)
    public void cubeToClient(JSONObject jsonObject, final CubeJSCallback callback) {

//        CubeService.instance().getApplication().setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );.startActivity(new Intent(CubeService.instance().getApplication(), MainActivity.class));
        startUserActivity(CubeService.instance().getApplication(), FastActivity.class);
//        Intent intent = new Intent();
//        intent.setClass(App.appContext, FastActivity.class);
//        startActivity(intent);

        // 向卡片发送回调
        if (callback != null) {
            callback.invoke("cubeToClient callback data: " + System.currentTimeMillis());
        }
    }

    /**
     * 启动新的Activity
     * @param context 当前Activity
     * @param cls     要启动的Activity的类
     */
    public static void startUserActivity(Context context , Class cls){
        Intent intent = new Intent();
        intent.setClass(context, cls);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
        context.startActivity(intent);

    }
}
